package com.example.demo02.mapstruct;

import org.mapstruct.Mapper;
import org.mapstruct.Named;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;


@Mapper(componentModel = "spring")
public interface DateFormatMapStruct {


    @Named(value = "handleEndTime")
    default Date handleEndTime(Date date) {
        if (date == null) {
            return null;
        }
        //ZoneId zoneId = TimeZone.getTimeZone("UTC").toZoneId();
        LocalDateTime dateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
        LocalDateTime addTime = dateTime.plusDays(1);
        date = Date.from(addTime.atZone(ZoneId.systemDefault()).toInstant());
        return date;
    }

    @Named(value = "handleStartTime")
    default Date handleStartTime(Date date) {
        if (date == null) {
            return null;
        }
        LocalDateTime dateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
        return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
}
